package com.lenovo.lcdm.dcm.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.toolkit.CollectionUtils;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.lenovo.lcdm.dcm.entity.DcmBusinessConfigurationCategoryC;
import com.lenovo.lcdm.dcm.mapper.DcmBusinessConfigurationCategoryCMapper;
import com.lenovo.lcdm.dcm.service.DcmBusinessConfigurationCategoryCService;
import org.springframework.cache.annotation.CacheEvict;
import org.springframework.cache.annotation.CachePut;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.HashSet;
import java.util.List;
import java.util.Set;
import java.util.stream.Collectors;

/**
* @author xujing30
* @description 针对表【dcm_business_configuration_category_c】的数据库操作Service实现
* @createDate 2024-01-22 12:55:48
*/
@Service
public class DcmBusinessConfigurationCategoryCServiceImpl extends ServiceImpl<DcmBusinessConfigurationCategoryCMapper, DcmBusinessConfigurationCategoryC>
    implements DcmBusinessConfigurationCategoryCService{

    @CachePut(value = {"BusinessConfiguration"}, keyGenerator = "categoryKeyGenerator")
    @Override
    public List<DcmBusinessConfigurationCategoryC> saveAll(List<DcmBusinessConfigurationCategoryC> entityList) {
        this.saveBatch(entityList);
        return entityList;
    }

    @CacheEvict(value = {"BusinessConfiguration"}, keyGenerator = "categoryKeyGenerator")
    @Override
    public boolean deleteAll() {
        LambdaQueryWrapper<DcmBusinessConfigurationCategoryC> deleteQw = new LambdaQueryWrapper<>();
        return this.remove(deleteQw);
    }

    @Override
    public boolean deleteById(Long id) {
        return this.removeById(id);

    }

    @Override
    @Cacheable(value = {"BusinessConfiguration"}, keyGenerator = "categoryKeyGenerator")
    public List<DcmBusinessConfigurationCategoryC> getAll() {
        return list();
    }

    @Override
    public DcmBusinessConfigurationCategoryC saveCategoryC(DcmBusinessConfigurationCategoryC category) {
        this.save(category);
        return category;
    }

    @Override
    public Set<String> getDistinctCategory() {
        Set<String> optionSet = new HashSet<>();
        QueryWrapper<DcmBusinessConfigurationCategoryC> qw = Wrappers.query();
        qw.select("distinct category");
        List<String> list = this.listObjs(qw);
        if(CollectionUtils.isNotEmpty(list)){
            optionSet = list.stream().filter(i->i != null && !i.equals("N/A")).collect(Collectors.toSet());
        }
        return optionSet;
    }

}




